//package org.springblade.modules.admin.service.feishu.impl;
//
//import org.springblade.common.utils.CookieUtil;
//import org.springblade.modules.admin.entity.CompanyElevator;
//import org.springblade.modules.admin.service.CompanyElevatorService;
//import org.springframework.stereotype.Component;
//import us.codecraft.webmagic.Page;
//import us.codecraft.webmagic.Site;
//import us.codecraft.webmagic.processor.PageProcessor;
//import us.codecraft.webmagic.selector.Html;
//
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * 抄坤哥的代码
// * 海纳百川 processor
// * @author: Sharry
// * @createTime: 2024-01-17 11:48
// * @version: Version-1.0
// */
//@Component
//public class HnbcProcessor implements PageProcessor {
//
//	public HnbcProcessor(CompanyElevatorService companyElevatorService) {
//		this.companyElevatorService = companyElevatorService;
//	}
//
//	private CompanyElevatorService companyElevatorService;
//
//	private Site site = Site
//		.me()
//		.setTimeOut(60000)
//		.setDomain("wsbj2.gdsei.org.cn")
//		.addHeader("Cookie", CookieUtil.getCookie())
//		.setSleepTime(1000);
//
//	@Override
//	public void process(Page page) {
//		List<CompanyElevator> companyElevatorList = new ArrayList<>();
//		List<String> questionList = page.getHtml().xpath("//*[@id=\"ec_table_body\"]/tr").all();
//		for (String s : questionList) {
//			Html tempHtml = Html.create("<table>" + s + "</table>");
//			CompanyElevator companyElevator = new CompanyElevator();
//			companyElevator.setDeviceCode(tempHtml.xpath("/html/body/table/tbody/tr/td[5]/text()").toString());
//			companyElevator.setDeviceType(tempHtml.xpath("/html/body/table/tbody/tr/td[15]/text()").toString());
//			companyElevator.setUseNum(tempHtml.xpath("/html/body/table/tbody/tr/td[6]/text()").toString());
//			companyElevator.setPrivateNum(tempHtml.xpath("/html/body/table/tbody/tr/td[7]/text()").toString());
//			companyElevator.setBuildingUser(tempHtml.xpath("/html/body/table/tbody/tr/td[4]/text()").toString());
//			companyElevator.setLocation(tempHtml.xpath("/html/body/table/tbody/tr/td[18]/text()").toString());
//			companyElevator.setCompanyNum(tempHtml.xpath("/html/body/table/tbody/tr/td[10]/text()").toString());
//			companyElevator.setNextCheckTime(tempHtml.xpath("/html/body/table/tbody/tr/td[17]/text()").toString());
//			companyElevator.setCheckResult(tempHtml.xpath("/html/body/table/tbody/tr/td[19]/text()").toString());
//			companyElevator.setUseStatus(tempHtml.xpath("/html/body/table/tbody/tr/td[11]/text()").toString());
//			companyElevator.setRegisterStatus(tempHtml.xpath("/html/body/table/tbody/tr/td[21]/text()").toString());
//
//			companyElevatorList.add(companyElevator);
//		}
//		page.putField("companyElevator", companyElevatorList);
//	}
//
//	@Override
//	public Site getSite() {
//		return site;
//	}
//}

import org.springblade.common.utils.CookieUtil;
import org.springblade.modules.admin.entity.CompanyElevator;
import org.springblade.modules.admin.service.CompanyElevatorService;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.processor.PageProcessor;
import us.codecraft.webmagic.selector.Html;

import java.util.ArrayList;
import java.util.List;

/**
 * 抄坤哥的代码
 * 海纳百川 processor
 * @author: Sharry
 * @createTime: 2024-01-17 11:48
 * @version: Version-1.0
 */
//@Component
public class HnbcProcessor implements PageProcessor {

	public HnbcProcessor(CompanyElevatorService companyElevatorService) {
		this.companyElevatorService = companyElevatorService;
	}

	private CompanyElevatorService companyElevatorService;

	private Site site = Site
		.me()
		.setTimeOut(60000)
		.setDomain("wsbj2.gdsei.org.cn")
		.addHeader("Cookie", CookieUtil.getCookie())
		.setSleepTime(1000);

	@Override
	public void process(Page page) {
		List<CompanyElevator> companyElevatorList = new ArrayList<>();
		List<String> questionList = page.getHtml().xpath("//*[@id=\"ec_table_body\"]/tr").all();
		for (String s : questionList) {
			Html tempHtml = Html.create("<table>" + s + "</table>");
			CompanyElevator companyElevator = new CompanyElevator();
			companyElevator.setDeviceCode(tempHtml.xpath("/html/body/table/tbody/tr/td[5]/text()").toString());
			companyElevator.setDeviceType(tempHtml.xpath("/html/body/table/tbody/tr/td[15]/text()").toString());
			companyElevator.setUseNum(tempHtml.xpath("/html/body/table/tbody/tr/td[6]/text()").toString());
			companyElevator.setPrivateNum(tempHtml.xpath("/html/body/table/tbody/tr/td[7]/text()").toString());
			companyElevator.setBuildingUser(tempHtml.xpath("/html/body/table/tbody/tr/td[4]/text()").toString());
			companyElevator.setLocation(tempHtml.xpath("/html/body/table/tbody/tr/td[18]/text()").toString());
			companyElevator.setCompanyNum(tempHtml.xpath("/html/body/table/tbody/tr/td[10]/text()").toString());
			companyElevator.setNextCheckTime(tempHtml.xpath("/html/body/table/tbody/tr/td[17]/text()").toString());
			companyElevator.setCheckResult(tempHtml.xpath("/html/body/table/tbody/tr/td[19]/text()").toString());
			companyElevator.setUseStatus(tempHtml.xpath("/html/body/table/tbody/tr/td[11]/text()").toString());
			companyElevator.setRegisterStatus(tempHtml.xpath("/html/body/table/tbody/tr/td[21]/text()").toString());

			companyElevatorList.add(companyElevator);
		}
		page.putField("companyElevator", companyElevatorList);
	}

	@Override
	public Site getSite() {
		return site;
	}
}
